package scanner;

import org.apache.commons.lang3.SystemUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Shunjie Ding on 2018/5/27.
 */
public final class Constants {
    public static final String HOME_PATH = System.getProperty("user.home");

    public static final String ANDROID_HOME =
        Paths.get(HOME_PATH, SystemUtils.IS_OS_MAC ? "Library/Android/Sdk" : "Android/Sdk")
            .toString();

    public static final String JAVA_HOME = System.getProperty("java.home");

    public static final String JAVA_RT_JAR = Paths.get(JAVA_HOME, "lib/rt.jar").toString();

    public static String getAndroidSourcePath(int androidVersion) {
        return Paths.get(ANDROID_HOME, "sources/android-" + androidVersion).toString() + "/";
    }

    public static String getAndroidJarPath(int androidVersion) {
        return Paths.get(ANDROID_HOME, "platforms/android-" + androidVersion, "android.jar")
            .toString();
    }

    public static final Set<String> UNCHECKED_EXCEPTIONS = new HashSet<>();
    static {
        String filepath = "./runtimeException.xls";
        Workbook wb;
        InputStream is;
        try {
            is = new FileInputStream(filepath);
            wb = new HSSFWorkbook(is);
            for (int index1 = 0; index1 < 2; index1++) {
                Sheet sheet = wb.getSheetAt(index1);
                int rowNum = sheet.getPhysicalNumberOfRows();
                for (int index = 0; index < rowNum; index++) {
                    Row row = sheet.getRow(index);
                    String cellData = row.getCell(0).getStringCellValue();
                    if (cellData.contains("exception")) {
                        UNCHECKED_EXCEPTIONS.add(cellData);
                    }
                }
            }
            UNCHECKED_EXCEPTIONS.add("java.lang.RuntimeException");
            wb.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /*(Arrays.asList(
        "android.icu.util.ICUUncheckedIOException", "java.io.UncheckedIOException",
        "java.nio.channels.AcceptPendingException", "java.nio.channels.AlreadyBoundException",
        "java.nio.channels.AlreadyConnectedException",
        "java.nio.file.ClosedDirectoryStreamException", "java.nio.file.ClosedFileSystemException",
        "java.nio.channels.ClosedSelectorException", "java.nio.file.ClosedWatchServiceException",
        "java.nio.channels.ConnectionPendingException", "java.nio.file.DirectoryIteratorException",
        "java.nio.channels.IllegalBlockingModeException",
        "java.nio.channels.IllegalChannelGroupException",
        "java.nio.charset.IllegalSelectorException",
        "java.nio.channels.IllegalCharsetNameException", "java.nio.InvalidMarkException",
        "java.nio.file.InvalidPathException", "java.nio.channels.NoConnectionPendingException",
        "java.nio.channels.NonWritableChannelException", "java.nio.channels.NotYetBoundException",
        "java.nio.channels.OverlappingFileLockException", "java.nio.file.ProviderMismatchException",
        "java.nio.ReadOnlyBufferException", "java.nio.channels.ReadPendingException",
        "java.nio.channels.UnsupportedAddressTypeException",
        "java.nio.channels.WritePendingException",
       "java.nio.charset.UnsupportedCharsetException"));*/
}
